package com.yoyuen.ioc;

import com.yoyuen.entity.Country;
import com.yoyuen.entity.Passenger;
//import com.yoyuen.entity.User;
//import org.junit.Test;
import com.yoyuen.entity.Robot;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.util.concurrent.ExecutorService;

public class FlightSystemTest {
    @Test
    public void test() {
        String xmlPath = "applicationContext.xml";
        ApplicationContext context = new ClassPathXmlApplicationContext(xmlPath);
        Country country = (Country) context.getBean("country");
        System.out.println(country.getCodeName());
        System.out.println(country.getName());
    }
//    按值注入
    @Test
    public void testPassenger(){
        String xmlPath = "src/main/resources/applicationContext.xml";
        ApplicationContext context = new FileSystemXmlApplicationContext(xmlPath);
        Passenger passenger = (Passenger) context.getBean("passenger");
        System.out.println(passenger.getCountry().getName());
        System.out.println(passenger.getCountry().getCodeName());
        System.out.println(passenger.getName());
        System.out.println(passenger.getCountry());
    }
//    构造方法注入
    @Test
    public void testPassenger2(){
        String xmlPath = "src/main/resources/applicationContext.xml";
        ApplicationContext context = new FileSystemXmlApplicationContext(xmlPath);
        Passenger passenger = (Passenger) context.getBean("passenger2");
        System.out.println(passenger.getCountry().getName());
        System.out.println(passenger.getCountry().getCodeName());
        System.out.println(passenger.getName());
        System.out.println(passenger.getCountry());

    }
//    实例化工厂
    @Test
    public void testRobot(){
        String xmlPath = "applicationContext.xml";
        ApplicationContext context = new ClassPathXmlApplicationContext(xmlPath);
        Robot robot = (Robot) context.getBean("robot");
        System.out.println(robot.getName());
    }

    @Test
    public void testES(){
        String xmlPath = "src/main/resources/applicationContext.xml";
        ApplicationContext context = new FileSystemXmlApplicationContext(xmlPath);
        ExecutorService es = (ExecutorService)context.getBean("executorService");
        System.out.println(es.getClass().getName());
    }

}
